package com.sinodata.atmp.components
{
	 import mx.controls.Image;
     import flash.utils.ByteArray;
     import flash.system.LoaderContext;
     import flash.display.Loader;
     import flash.display.DisplayObject;
     import flash.events.Event;

     public class ByteArrayImage extends mx.controls.Image
     {
           private var _loader:Loader = new Loader();
           
           public function Image():void {
           		this.scaleContent = false;
           }
           
           override protected function createChildren():void {
                 addChild(_loader);
           }
           
           public function loadBytes(bytes:ByteArray, context:LoaderContext = null):void {
	           	if(bytes != null){
	           		this.source = "";
	                 _loader.loadBytes(bytes, context);	  
	                 _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);               
	            }else{
	            	this.source="Images/nophoto.jpg"
	            }
           }
           
           public function onLoadComplete(event:Event):void{
           	  this.width = event.target.width;
           	  this.height = event.target.height;
           }
     }
}